package com.chapter.sample.juc;

import java.util.concurrent.*;

public class CompletableFutureDemo {
    public static void main(String[] args) {
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                8,
                16,
                10,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());

        CompletableFuture.supplyAsync(() -> {
            return 1;
        }, poolExecutor).thenApply(f -> {
            return f + 2;
        });

        poolExecutor.shutdown();
    }

    private static void m1(ThreadPoolExecutor poolExecutor) {
        CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
        });
        CompletableFuture.runAsync(() -> {
            System.out.println(Thread.currentThread().getName());
        }, poolExecutor);

        CompletableFuture.supplyAsync(() -> {
            return "a";
        });
    }
}
